﻿
/// <reference path="drafts/IntelliSenseHelper.js" />
/*!
// A part of "Nana Script Utilities", accept the license at http://nana.codeplex.com/license before use it in your own products.
// 这是《Nana脚本工具箱》的一部分，在您自己的产品中使用以前先接受这个使用许可：http://nana.codeplex.com/license
*/

function NanaCore(opts) {
  /// <summary>** Initialize the Nana Framework, with options or not. **</summary>
  var g = this, undefined;
  var src = {};

  //========//========
  // Namespace
  function Namespace(ns) {
    if (!(this instanceof Namespace))
      return new Namespace(ns);

    var a = (ns + "").split(".");
    var subname = a.pop();

    var parent = a.length ? Namespace(a.join(".")) : parent = g;

    var nsObj;
    if (nsObj = parent[subname])
      return nsObj;
    else {
      this.valueOf = function () {
        return ns;
      };
      return parent[subname] = this;
    }
  }
  Namespace.prototype.toString = function () {
    return "<Namespace: " + this.valueOf() + ">";
  };
  src.Namespace = Namespace;
  //========

  //========//========
  // Fully qualified name
  var qName = src.qName = $fqname = opts && opts.qName || _$7qName;

  //========//========
  // Members setup
  function applyMembers(target, source, all) {
    /// <summary>Apply members the source object has and name them with.</summary>

    if (all) {
      for (var n in source)
        target[qName(n)] = source[n];
    } else {
      for (var n in source) {
        if (source.propertyIsEnumerable(n))
          target[qName(n)] = source[n];
      }
    }
  } // applyMembers
  src.applyMembers = applyMembers;
  applyMembers(g, src);
  //========//========

  //========//========
  var objProto = Object.prototype;
}

//========
!function (g) {
  var s = [];
  NanaCore.popQuest = function () {
    return s.shift();
  };
  NanaCore.delayRun = function (f) {
    g._nanaDelayExec();
    return s.push(f);
  };
  NanaCore.queueJob = function (f) {
    return s.push(f);
  };
} (this);
//========


NanaCore.defName = function _qName(n) {
  /// <summary>Get fully qualified name. 
  /// This implementation just return the parameter passed to it.</summary>
  return n;
};
NanaCore.$qName = function _$qName(n) {
  /// <summary>Get fully qualified name. 
  /// This implementation will give a "$" prefix.</summary>
  return "$" + n;
};
NanaCore.$7qName = function _$7qName(n) {
  /// <summary>Get fully qualified name. 
  /// This implementation will give a "$7" prefix.</summary>
  return "$7" + n;
};


this._nanaInitialized && _nanaInitialized();
